package test.study.concurrent.thread._5_sync.latch;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;

@Slf4j
public class _1_CountDownLatch_Main {

    public static void main(String[] args) {
        //step-1:
        CountDownLatch latch = new CountDownLatch(2);

        //step-2:
        new Thread(() -> {
            try {
                log.info("asdfasdf");
                ThreadUtil.sleep(5000);
            } finally {
                //step-3:
                latch.countDown();
            }
        }).start();
        new Thread(() -> {
            log.info("12312312");
            ThreadUtil.sleep(2000);
            latch.countDown();
        }).start();

        //step-4:
        try {
            latch.await();
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
}
